///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package scheduling;
//
//import facades.CandidateFacade;
//import entities.Candidate;
//import entities.Notification;
//import entities.NotificationType;
//import facades.NotificationFacade;
//import facades.NotificationTypeFacade;
//import java.io.IOException;
//import java.net.URISyntaxException;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import java.util.Properties;
//import java.util.Random;
//import javax.ejb.Schedule;
//import javax.ejb.Stateless;
//import javax.ejb.TransactionManagement;
//import javax.ejb.TransactionManagementType;
//import javax.inject.Inject;
//import mail.EmailEJB;
//import mail.EmailTemplateHelper;
//import mail.datamodel.IdDataSource;
//import org.primefaces.push.PushContext;
//import org.primefaces.push.PushContextFactory;
//import util.DateConverter;
//import util.MessagesHelper;
//
///**
// *
// * @author damfercer
// */
//@TransactionManagement(value=TransactionManagementType.BEAN)
//@Stateless
//public class RandomVisitedNotification {
//    @Inject
//    CandidateFacade candidateFacade;
//    @Inject
//    NotificationFacade notificationFacade;
//    @Inject
//    NotificationTypeFacade notificationTypeFacade;
//    private Random randomGenerator;
//    @Inject
//    EmailEJB emailEJB;
//    
//    public RandomVisitedNotification(){
//        randomGenerator= new Random();
//    }
//    
//    @Schedule( minute="*/5", hour="10,11,12,13", dayOfWeek="Mon,Tue,Wed,Thu,Fri", persistent=false)
//    public void sendRandomVisitedNotification() throws IOException, URISyntaxException {
//        List<Candidate> candidateList=candidateFacade.getFilteredCandidates("");
//        int randomIndexListValidCandidates = randomGenerator.nextInt(candidateList.size());
//        Candidate selectedCandidate= candidateList.get(randomIndexListValidCandidates);
////        Candidate selectedCandidate= candidateFacade.find(3102);//3102
//
//        Properties properties= MessagesHelper.getPropertyFromCandidate(selectedCandidate);
//        int randomSectorCompany = randomGenerator.nextInt(3);
//        String companysector;
//        if (randomSectorCompany==0){
//            companysector=properties.getProperty("FashionCompany");
//        }
//        else if(randomSectorCompany==1){
//            companysector=properties.getProperty("HospitalityCompany");
//        }
//        else{
//            companysector=properties.getProperty("RetailCompany");
//        }
//        //notificación
//        StringBuilder mensajeNotificacion=new StringBuilder();
//        mensajeNotificacion.append(companysector);
//        mensajeNotificacion.append(" ");
//        mensajeNotificacion.append(properties.getProperty("ProfileVisited"));
//        mensajeNotificacion.append(" ");
//        mensajeNotificacion.append(DateConverter.convertDateToString(new Date()));
//        Notification notification=new Notification();
//        notification.setIsNotificated(false);
//        notification.setDescription(mensajeNotificacion.toString());
//        notification.setDate(new Date());
//        notification.setUserSender(null);
//        notification.setUser(selectedCandidate.getUser());
//        NotificationType notificationType= notificationTypeFacade.find(3);
//        notification.setNotificationType(notificationType);
//        notificationFacade.create(notification);
//        //enviar push 
//        PushContext pushContext = PushContextFactory.getDefault().getPushContext();
//        String channel="/notification/"+notification.getUser().getIdUser().toString();
//        pushContext.push(channel, notification.getIdNotification().toString());
//        //enviar email 
//        if(notification.getUser().getCandidate().getCandidateConfiguration()==null){
//            throwEmailCandidate(notification);
//        }
//        else if(notification.getUser().getCandidate().getCandidateConfiguration().getEmailVisited()){
//            throwEmailCandidate(notification);
//        }
//    }
//
//    
//    
//    public void throwEmailCandidate(Notification notification) throws IOException, URISyntaxException{
//        String subject="";
//        String html="";
//        
//
//        subject="TheRecruitery. "+notification.getDescription().substring(0, notification.getDescription().length()-19);
//        html=EmailTemplateHelper.getHtmlHeader()+EmailTemplateHelper.getHtmlDivText(notification.getDescription().substring(0, notification.getDescription().length()-19)+".")+EmailTemplateHelper.getHtmlDivText(MessagesHelper.getMessage("VisitedProfileText", notification.getUser()))+EmailTemplateHelper.getHtmlDivText(MessagesHelper.getMessage("VisitedAdquiredProfileText2", notification.getUser())+EmailTemplateHelper.getHtmlDivText(EmailTemplateHelper.getSocialNetworkFooter()));
//
//        
//        List<IdDataSource> dataSources=new ArrayList<IdDataSource>();
//        dataSources.add(new IdDataSource(EmailTemplateHelper.getFileDataSourceFromURL(Thread.currentThread().getContextClassLoader().getResource("emailLogo.png")), EmailTemplateHelper.logoId));
//        emailEJB.sendHtmlMail(notification.getUser().getEmail(), subject, html, dataSources);
//        
//    }
//    
//
//
//}
